<template>
  <div class="user-info-card">
    <div class="user-header">
      <div class="user-avatar">
        <img :src="userAvatar" :alt="username" />
      </div>
      <div class="user-details">
        <h3 class="username">{{ username }}</h3>
        <p v-if="bio" class="bio">{{ bio }}</p>
        <div v-if="isLoggedIn" class="user-stats">
          <div class="stat-item">
            <span class="stat-value">{{ formatNumber(stats.articles) }}</span>
            <span class="stat-label">文章</span>
          </div>
          <div class="stat-item">
            <span class="stat-value">{{ formatNumber(stats.followers) }}</span>
            <span class="stat-label">粉丝</span>
          </div>
          <div class="stat-item">
            <span class="stat-value">{{ formatNumber(stats.following) }}</span>
            <span class="stat-label">关注</span>
          </div>
        </div>
      </div>
    </div>
    
    <div v-if="!isLoggedIn" class="login-section">
      <van-button type="primary" block @click="$emit('login')">登录 / 注册</van-button>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useUserStore } from '../../store/user'
import { formatNumber } from '../../utils/common'

const props = defineProps({
  bio: {
    type: String,
    default: ''
  },
  stats: {
    type: Object,
    default: () => ({
      articles: 0,
      followers: 0,
      following: 0
    })
  }
})

defineEmits(['login'])

const userStore = useUserStore()
const isLoggedIn = computed(() => userStore.isLoggedIn)
const username = computed(() => userStore.username)
const userAvatar = computed(() => userStore.userAvatar)
</script>

<style lang="scss" scoped>
.user-info-card {
  background-color: var(--background-color-light);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--box-shadow);
  
  .user-header {
    display: flex;
    align-items: center;
    
    .user-avatar {
      width: 64px;
      height: 64px;
      border-radius: 50%;
      overflow: hidden;
      margin-right: 16px;
      flex-shrink: 0;
      
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }
    
    .user-details {
      flex: 1;
      
      .username {
        font-size: 18px;
        font-weight: 500;
        color: var(--text-color);
        margin-bottom: 4px;
      }
      
      .bio {
        font-size: 14px;
        color: var(--text-color-secondary);
        margin-bottom: 8px;
      }
      
      .user-stats {
        display: flex;
        
        .stat-item {
          display: flex;
          flex-direction: column;
          align-items: center;
          margin-right: 16px;
          
          .stat-value {
            font-size: 16px;
            font-weight: 500;
            color: var(--text-color);
          }
          
          .stat-label {
            font-size: 12px;
            color: var(--text-color-tertiary);
          }
        }
      }
    }
  }
  
  .login-section {
    margin-top: 16px;
  }
}
</style> 